<?php
include_once("config.php");
if (isset($_SESSION['adminName'])){
	$isAdmin=true;
}else{
	$isAdmin=false;
}
if ($isAdmin){
	if (isset($_POST['restuarantaddress'])){
		$isInputValid=true;
		$restuarantaddress=mysql_real_escape_string(stripcslashes($_POST['restuarantaddress']));
	}else{
		$isInputValid=false;
	}
}else{
	header("location: adminIndex.php");
}
if ($isInputValid){
	$query="SELECT * FROM restaurant WHERE address='$restuarantaddress'";
  $result1=mysql_query($query);
  $rowCount=mysql_num_rows($result1);
  if ($rowCount==1){
  	$canUpdate=true;
  	$row=mysql_fetch_array($result1);
  }
  else{
  	$canUpdate=false;
  }
}else{
	$canUpdate=false;
}
?>

<!DOCTYPE html>
<html>
<head>
	<title>Update Restuarant | Admin</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
	<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
	<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
</head>
<body>
<?php
if ($canUpdate){
?>
	<div class="container">
  	<form class="form-horizontal" role="form" action="checkUpdaterestuarant.php" method="post">
  	  <div class="form-group">
		    <label class="col-sm-2 control-label">Restuarant Name</label>
		    <div class="col-sm-10">
		      <?php
		      echo "<input type='text' class='form-control' name='restuarantname' value='".$row['name']."' placeholder='New Restuarant Name'>";
		      ?>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label">Restuarant Address</label>
		    <div class="col-sm-10">
		      <?php
		      echo $row['address'];
		      ?>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label">Average Consumption</label>
		    <div class="col-sm-10">
		      <?php
		      echo "<input type='text' class='form-control' name='restuarantaverageconsumption' value='".$row['argC']."' placeholder='New Average Consumption'>";
		      ?>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label">Cuisines</label>
		    <div class="col-sm-10">
		      <?php
		      echo "<input type='text' class='form-control' name='restuarantcuisines' value='".$row['cuisines']."' placeholder='New Restuarant Cuisines'>";
		      ?>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label">Contact Number</label>
		    <div class="col-sm-10">
		      <?php
		      echo "<input type='text' class='form-control' name='restuarantcontactnumber' value='".$row['contactNum']."' placeholder='New Restuarant Contact Number'>";
		      ?>
		    </div>
		  </div>
		  <div class="form-group">
		    <label class="col-sm-2 control-label">Description</label>
		    <div class="col-sm-10">
		      <?php
		      echo "<input type='text' class='form-control' name='restuarantdescription' value='".$row['description']."' placeholder='New Restuarant Description'>";
		      ?>
		    </div>
		  </div>
		  <?php
		  echo "<input type='hidden' value='".$row['address']."' name='restuarantaddress'>";
		  ?>
		  <div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <button type="submit" class="btn btn-success">Update Restuarant</button>
		    </div>
		  </div>
		</form>
	</div>
<?php
}else{
  echo "cannot update the restuarant because of corrupted data";
}
?>
</body>
</html>

